package com.AAA.service.Impl.mht;

import com.AAA.dao.mht.ITmhtRecordMapper;
import com.AAA.entity.MyPage;
import com.AAA.entity.mht.TMht;
import com.AAA.entity.mht.TMhtRecord;
import com.AAA.service.mht.ITmhtRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TmhtRecordServiceImpl implements ITmhtRecordService {
    @Autowired
    private ITmhtRecordMapper mapper;
    @Override
    public TMhtRecord checkrecord(String tel) {
        TMhtRecord tMhtRecord = new TMhtRecord();
        tMhtRecord.setTel(tel);
        List<TMhtRecord> i = mapper.select(tMhtRecord);
        if (i.size()==0){
            return null;
        }
        return i.get(0);
    }

    @Override
    public Integer add(TMhtRecord tMhtRecord) {
        tMhtRecord.setCreatetime(new Date());
        int insert = mapper.insert(tMhtRecord);
        return tMhtRecord.getId();
    }

    @Override
    public PageInfo queryall(MyPage myPage, TMhtRecord tMhtRecord) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<TMhtRecord> queryall = mapper.queryall(tMhtRecord);
        PageInfo pageInfo = new PageInfo(queryall);
        return pageInfo;
    }
}
